﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DfMvc.Models;
using Df.Common.Forms;

namespace DfMvc.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            DfDataContext context = new DfDataContext();
            var model = context.Blogs.Include("DForm").SingleOrDefault(b => b.Id == 1015);
            return View(model);
        }

        [HttpPost]
        public ActionResult Index(Blog form)
        {
            var context = new DfDataContext();
            var blog = context.Blogs.Include("DForm").SingleOrDefault(b => b.Id == form.Id);
            blog.Title = form.Title;
            blog.Description = form.Description;
            blog.DForm.JsonElements = form.DForm.JsonElements;

            context.SaveChanges();

            //context.Entry(form).State = EntityState.Modified;
            return View(blog);
        }

    }
}
